﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CanDoo.Data.Entity;
using CanDoo.Oil.Core.Models;
using System.Data.Entity.Infrastructure.Annotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace CanDoo.Oil.Core.ModelConfigurations
{
    /// <summary>
    /// 实体类-数据表映射——商品
    /// </summary>
    public class ProductConfiguration : EntityConfigurationBase<Product>
    {
        /// <summary>
        /// 初始化一个<see cref="ProductConfiguration"/>类型的新实例
        /// </summary>
        public ProductConfiguration()
        {
            ToTable("pro_Product");
            this.Property(p => p.ProductTypeId).HasColumnName("ProductTypeId");
            this.HasRequired(p => p.ProductType).WithMany().HasForeignKey(p => p.ProductTypeId).WillCascadeOnDelete(false);

            this.Property(p => p.BrandId).HasColumnName("BrandId");
            this.HasRequired(p => p.Brand).WithMany().HasForeignKey(p => p.BrandId).WillCascadeOnDelete(false);

            this.Property(p => p.DefaultSupplierId).HasColumnName("DefaultSupplierId");
            this.HasOptional(p => p.DefaultSupplier).WithMany().HasForeignKey(p => p.DefaultSupplierId).WillCascadeOnDelete(false);

            this.Property(p => p.ProductUnitId).HasColumnName("ProductUnitId");
            this.HasRequired(p => p.ProductUnit).WithMany().HasForeignKey(p => p.ProductUnitId).WillCascadeOnDelete(false);



            this.Property(p => p.SN).IsRequired().HasMaxLength(new int?(50))
                .HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UX_pro_Product_SN") { IsUnique = true }));

        }
    }
}
